package main

import (
	"fmt"
	"strings"
)

func canBeTypedWords(text string, brokenLetters string) int {
	return method1(text, brokenLetters)
}

// 假设每个单词都能输入，遇到某个单词无法输入再将其排除
func method1(text, brokenLetters string) (count int) {
	if text == "" {
		return 
	}

	words := strings.Split(text, " ")
	count = len(words)

	// 键盘完好无损，全部单词都能输入
	if brokenLetters == "" {
		return
	}

	detected := false
	for _, word := range words {
		for _, letter := range word {
			if strings.Contains(brokenLetters, string(letter)) {
				detected = true
				break
			}
		}

		// 排除无法输入的单词
		if detected {
			count--
			detected = false
		}
	}

	return

}

func method2(text, brokenLetters string) int {
	result := 0
	canBeInput := true
	for _, character := range text {
		if character == ' ' {
			if canBeInput {
				result++
			}
			canBeInput = true
		} else if strings.Contains(brokenLetters, string(character)) {
			canBeInput = false
		}
	}

	if canBeInput {
		result++
	}

	return result
}

func main() {
	text := "leet code"
	brokenLetters := "lt"
	fmt.Println(canBeTypedWords(text, brokenLetters))
	fmt.Println(method2(text, brokenLetters))
}
